package com.maoxianzhe.gonghui.user.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.maoxianzhe.gonghui.common.Exception.BusinessException;
import com.maoxianzhe.gonghui.common.constant.BusinessConstant;
import com.maoxianzhe.gonghui.user.Mapper.UserMapper;
import com.maoxianzhe.gonghui.user.pojo.DTO.UserLoginDTO;
import com.maoxianzhe.gonghui.user.pojo.User;
import com.maoxianzhe.gonghui.user.pojo.VO.UserLoginVO;
import com.maoxianzhe.gonghui.user.service.UserService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public UserLoginVO userlogin(UserLoginDTO userLoginDTO) {
        User user = userMapper.QueryStudentByStudentId(userLoginDTO.getStudentId());
        if(user == null){
            throw new BusinessException(BusinessConstant.USER_IS_NULL);
        }
        String password = user.getPassword();
        if(!(userLoginDTO.getPassword()).equals(password)){
            throw new BusinessException(BusinessConstant.USER_OR_PASSWORD_IS_ERROR);
        }
        UserLoginVO userLoginVO = new UserLoginVO();
        if (userLoginDTO.getStudentId().equals(user.getStudentId())){
            BeanUtil.copyProperties(user,userLoginVO);
        }
        return userLoginVO;
    }
}
